package dto

import (
	"tuowei.com/app/admin/models"
	"tuowei.com/common/dto"
	common "tuowei.com/common/models"
)

type SysMaterialGetPageReq struct {
	dto.Pagination `search:"-"`
	Name           string `form:"name" search:"type:contains;column:name;table:sys_material" comment:"资料名称"`
	StartTime      string `search:"type:gte;column:created_at;table:sys_material" form:"beginTime"`
	EndTime        string `search:"type:lte;column:created_at;table:sys_material" form:"endTime"`
	Status         int    `form:"status" search:"type:exact;column:status;table:sys_material" comment:"资料状态"`
	Category       string `form:"category" search:"type:exact;column:category;table:sys_material" comment:"资料分类"`
	Subject        string `form:"subject" search:"type:exact;column:subject;table:sys_material" comment:"资料科目"`
	Province       string `form:"province" search:"type:contains;column:province;table:sys_material" comment:"适用地区"`
	Type           string `form:"type" search:"type:exact;column:type;table:sys_material" comment:"资料类型"`
}

func (m *SysMaterialGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type SysMaterialInsertReq struct {
	Id           int     `json:"id" comment:"主键ID"`
	Name         string  `json:"name" comment:"资料名称" vd:"@:len($)>0; msg:'资料名称不能为空'"`
	Type         string  `json:"type" comment:"资料类型" vd:"@:len($)>0; msg:'请选择资料类型'"`
	Category     string  `json:"category" comment:"资料分类" vd:"@:len($)>0; msg:'请选择资料分类'"`
	Subject      string  `json:"subject" comment:"资料科目" vd:"@:len($)>0; msg:'请选择资料科目'"`
	Cover        string  `json:"cover" comment:"封面" vd:"@:len($)>0; msg:'请上传资料封面'"`
	Sum          int     `json:"sum" comment:"资料数量" vd:"$>0; msg:'请填写资料数量'"`
	Status       int     `json:"status" comment:"资料状态"`
	Price        float32 `json:"price" comment:"资料价格" vd:"$>0; msg:'请填写资料价格'"`
	Introduction string  `json:"introduction" comment:"资料简介" vd:"@:len($)>0; msg:'一句话介绍资料'"`
	Postage      float32 `json:"postage" comment:"资料邮费"`
	Province     string  `json:"province" comment:"适用地区" vd:"@:len($)>0; msg:'请选择适用地区'"`
	LBTUrl       string  `json:"lbt_url" gorm:"type:varchar(5000);comment:轮播图地址"`
	common.ControlBy
}

func (s *SysMaterialInsertReq) Generate(model *models.SysMaterial) {
	model.Name = s.Name
	model.Introduction = s.Introduction
	model.Price = s.Price
	model.Cover = s.Cover
	model.Status = s.Status
	model.Subject = s.Subject
	model.Type = s.Type
	model.Postage = s.Postage
	model.Category = s.Category
	model.Sum = s.Sum
	model.CreateBy = s.CreateBy
	model.Creator = s.Creator
	model.Province = s.Province
	model.LBTUrl = s.LBTUrl

}

func (s *SysMaterialInsertReq) GetId() interface{} {
	return s.Id
}

type SysMaterialUpdateReq struct {
	Id           int     `json:"id" comment:"主键ID" vd:"$>0; msg:'要更新的资料ID不能为空'"`
	Name         string  `json:"name" comment:"资料名称" vd:"@:len($)>0; msg:'资料名称不能为空'"`
	Type         string  `json:"type" comment:"资料类型" vd:"@:len($)>0; msg:'请选择资料类型'"`
	Category     string  `json:"category" comment:"资料分类" vd:"@:len($)>0; msg:'请选择资料分类'"`
	Subject      string  `json:"subject" comment:"资料科目" vd:"@:len($)>0; msg:'请选择资料科目'"`
	Cover        string  `json:"cover" comment:"封面" vd:"@:len($)>0; msg:'请上传资料封面'"`
	Status       int     `json:"status" comment:"资料状态"`
	Sum          int     `json:"sum" comment:"资料数量" vd:"$>0; msg:'请填写资料数量'"`
	Price        float32 `json:"price" comment:"资料价格" vd:"$>0; msg:'请填写资料价格'"`
	Introduction string  `json:"introduction" comment:"资料简介" vd:"@:len($)>0; msg:'一句话介绍资料'"`
	Postage      float32 `json:"postage" comment:"资料邮费"`
	Province     string  `json:"province" comment:"适用地区" vd:"@:len($)>0; msg:'请选择适用地区'"`
	LBTUrl       string  `json:"lbt_url" gorm:"type:varchar(5000);comment:轮播图地址"`
	common.ControlBy
}

func (s *SysMaterialUpdateReq) Generate(model *models.SysMaterial) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Name = s.Name
	model.Introduction = s.Introduction
	model.Price = s.Price
	model.Cover = s.Cover
	model.Status = s.Status
	model.Subject = s.Subject
	model.Type = s.Type
	model.Postage = s.Postage
	model.Category = s.Category
	model.Sum = s.Sum
	model.UpdateBy = s.UpdateBy
	model.Updater = s.Updater
	model.Province = s.Province
	model.LBTUrl = s.LBTUrl
}

func (s *SysMaterialUpdateReq) GetId() interface{} {
	return s.Id
}

type SysMaterialById struct {
	dto.ObjectById
	common.ControlBy
}

type SysMaterialUpdateStatusReq struct {
	Id     int `json:"id" vd:"$>0; msg:'更新ID不能为空'"`
	Status int `json:"status"`
	common.ControlBy
}

func (s *SysMaterialUpdateStatusReq) Generate(model *models.SysMaterialUpdateStatus) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Status = s.Status

	model.UpdateBy = s.UpdateBy
	model.Updater = s.Updater
}

func (s *SysMaterialUpdateStatusReq) GetId() interface{} {
	return s.Id
}
